package com.fmenu.web.controller.bns;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fmenu.common.annotation.Log;
import com.fmenu.common.core.controller.BaseController;
import com.fmenu.common.core.domain.AjaxResult;
import com.fmenu.common.enums.BusinessType;
import com.fmenu.system.domain.BnsAccessory;
import com.fmenu.system.service.IBnsAccessoryService;
import com.fmenu.common.utils.poi.ExcelUtil;
import com.fmenu.common.core.page.TableDataInfo;

/**
 * 配料Controller
 *
 * @author zhangrui
 * @date 2021-12-22
 */
@RestController
@RequestMapping("/system/accessory")
public class BnsAccessoryController extends BaseController {
    @Autowired
    private IBnsAccessoryService bnsAccessoryService;

    /**
     * 查询配料列表
     */
    @PreAuthorize("@ss.hasPermi('bns:accessory:list')")
    @GetMapping("/list")
    public TableDataInfo list(BnsAccessory bnsAccessory) {
        startPage();
        List<BnsAccessory> list = bnsAccessoryService.selectBnsAccessoryList(bnsAccessory);
        return getDataTable(list);
    }

    /**
     * 导出配料列表
     */
    @PreAuthorize("@ss.hasPermi('bns:accessory:export')")
    @Log(title = "配料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BnsAccessory bnsAccessory) {
        List<BnsAccessory> list = bnsAccessoryService.selectBnsAccessoryList(bnsAccessory);
        ExcelUtil<BnsAccessory> util = new ExcelUtil<BnsAccessory>(BnsAccessory.class);
        util.exportExcel(response, list, "配料数据");
    }

    /**
     * 获取配料详细信息
     */
    @PreAuthorize("@ss.hasPermi('bns:accessory:query')")
    @GetMapping(value = "/{accessoryId}")
    public AjaxResult getInfo(@PathVariable("accessoryId") Long accessoryId) {
        return AjaxResult.success(bnsAccessoryService.selectBnsAccessoryByAccessoryId(accessoryId));
    }

    /**
     * 新增配料
     */
    @PreAuthorize("@ss.hasPermi('bns:accessory:add')")
    @Log(title = "配料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BnsAccessory bnsAccessory) {
        return toAjax(bnsAccessoryService.insertBnsAccessory(bnsAccessory));
    }

    /**
     * 修改配料
     */
    @PreAuthorize("@ss.hasPermi('bns:accessory:edit')")
    @Log(title = "配料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BnsAccessory bnsAccessory) {
        return toAjax(bnsAccessoryService.updateBnsAccessory(bnsAccessory));
    }

    /**
     * 删除配料
     */
    @PreAuthorize("@ss.hasPermi('bns:accessory:remove')")
    @Log(title = "配料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{accessoryIds}")
    public AjaxResult remove(@PathVariable Long[] accessoryIds) {
        return toAjax(bnsAccessoryService.deleteBnsAccessoryByAccessoryIds(accessoryIds));
    }
}
